package org.alvin.gencode;

import lombok.extern.slf4j.Slf4j;
import org.alvin.mini_inject.InjectContext;
import org.alvin.mini_inject.annotations.MiniServiceScan;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author tangzc
 */
@Slf4j
@MiniServiceScan({"org.alvin.gencode.inters", "org.alvin.gencode.run.service", "org.alvin.gencode.run.code"})
@Mojo(name = "inter-doc", defaultPhase = LifecyclePhase.NONE)
public class GenInterfaceMavenPlugin extends AbstractMojo {

    @Parameter
    private String config;

    @Override
    public void execute() {
        System.getProperties().put("config", this.config);
        InjectContext.run(GenInterfaceMavenPlugin.class, new String[]{this.config});
    }

    public static void main(String[] args) {
//        String path = System.getProperty("user.dir").concat(File.separator).concat("src").concat(File.separator).concat("config").concat(File.separator).concat("config.properties");
//        System.getProperties().put("config", path);
//        InjectContext.run(GenInterfaceMavenPlugin.class, args);
        String regex = "^(\\-1)|([1-9]\\d*(\\.\\d+)?)$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher("-1");
        System.out.println("-1 == " + matcher.matches());
        matcher = pattern.matcher("-2");
        System.out.println("-2 == " + matcher.matches());
        matcher = pattern.matcher("-3");
        System.out.println("-3 == " + matcher.matches());
        matcher = pattern.matcher("0");
        System.out.println("0 == " + matcher.matches());
        matcher = pattern.matcher("1");
        System.out.println("1 == " + matcher.matches());
        matcher = pattern.matcher("11");
        System.out.println("11 == " + matcher.matches());
        matcher = pattern.matcher("11.001");
        System.out.println("11.001 == " + matcher.matches());
        matcher = pattern.matcher("1121231231.001");
        System.out.println("1121231231.001 == " + matcher.matches());
        matcher = pattern.matcher("1121231231.");
        System.out.println("1121231231. == " + matcher.matches());
        matcher = pattern.matcher("1121231231.00");
        System.out.println("1121231231.00 == " + matcher.matches());
        matcher = pattern.matcher("1121231231.001121231231");
        System.out.println("1121231231.001121231231 == " + matcher.matches());
    }
}
